package com.wang.exam.controller;

import com.wang.exam.pojo.Grade;
import com.wang.exam.service.StudentGradeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StudentGradeController {
    private String test_name;
    @Autowired
    StudentGradeService studentGradeService;
    @RequestMapping("/studentGradeLists")
    @ResponseBody
    public Object getGradeLists(HttpSession httpSession){
        Map<String,Object> m = new HashMap<String,Object>();
        m.put("major_id",(Integer) httpSession.getAttribute("major_id"));
        m.put("student_id",(Integer) httpSession.getAttribute("student_id"));
        List<Grade> list = studentGradeService.getGradeLists(m);
        return list;
    }
    @RequestMapping("/studentsGradesLists")
    @ResponseBody
    public Object getStudentsGradesLists(){
        return studentGradeService.getStudentsGrades();
    }
    @RequestMapping("/up_student_grade")
    @ResponseBody
    public Object upStudentsGradesLists(@Param("student_id")Integer student_id,
                                        @Param("course_id")Integer course_id,
                                        @Param("grade")Integer grade){
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,String> maps = new HashMap<String,String>();
        map.put("student_id",student_id);
        map.put("course_id",course_id);
        map.put("grade",grade);
        try {
            int x = studentGradeService.upStudentsGradesLists(map);
            maps.put("code","200");
            maps.put("msg","修改成功！");
            return maps;
        }catch (Exception e){
            e.printStackTrace();
            maps.put("code","200");
            maps.put("msg","修改失败！");
            return maps;
        }

    }
    @RequestMapping("/de_student_grade")
    @ResponseBody
    public Object DeleteStudentsGradesLists(@Param("student_id")Integer student_id,
                                        @Param("course_id")Integer course_id){
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,String> maps = new HashMap<String,String>();
        map.put("student_id",student_id);
        map.put("course_id",course_id);
        try {
            int x = studentGradeService.deleteStudentsGradesLists(map);
            maps.put("code","200");
            maps.put("msg","删除成功！");
            return maps;
        }catch (Exception e){
            e.printStackTrace();
            maps.put("code","200");
            maps.put("msg","删除失败！");
            return maps;
        }

    }
}
